%% FIGURE 3
clear all
clc
% Add path 
% Determine where your m-file's folder is.
folder = fileparts(which("Figure_3.m")); 
% Add that folder plus all subfolders to the path.
addpath(genpath(folder)); 

% Saving path
file_dir = what('Figures'); 
spath=file_dir.path;

% Setting
hor=10;
jhor=0:hor;
Run_color_settings
% LOAD DATA
load("Results/AR1DGP_06.mat");

% Plot
clf
N_plot=2;
pln=1;
plotColumns=2;
figure(1)
for j=1:N_plot
            grid on
            pl=subplot(ceil(N_plot/plotColumns),plotColumns,pln);
            hold on
            
           if j==1
           % Coverage rate
            plot(0:hor,0.95*ones(size(1:hor+1)),'k','LineWidth',2)
            p0=plot(jhor,Results.CV.Pool.seqblock', '-','LineWidth',4,'Color', line_colors(3,:)); 
            p1=plot(jhor,Results.CV.Pool.bootrep', '--','LineWidth',4,'Color', line_colors(1,:)); 
            hold off; axis tight
            xlim([0 hor]);
            set(gca,'XTick',0:2:hor,'XTickLabel',cellstr(num2str((0:2:hor)')),'Layer','top','FontSize',14)
            xlabel('Horizon')  
            lh=legend([p0 p1],{'Sequence of block';'Residual based'},'FontSize',16,'Location','southwest','Box','off');
            ylim([0 1]) 
            yticks(0:0.2:1)
            title('Coverage Rate','FontSize',16,'FontWeight','normal')

           % Average length
           elseif j==2
            p0=plot(jhor,Results.AL.Pool.seqblock', '-','LineWidth',3,'Color', line_colors(3,:)); 
            p1=plot(jhor,Results.AL.Pool.bootrep', '--','LineWidth',3,'Color', line_colors(1,:)); 
            hold off; axis tight
            xlim([0 hor]);
            set(gca,'XTick',0:2:hor,'XTickLabel',cellstr(num2str((0:2:hor)')),'Layer','top','FontSize',14)
            xlabel('Horizon')  
            ylim([0.32 0.52]) 
            yticks(0.32:0.05:0.52)
            title('Average Length','FontSize',16,'FontWeight','normal')
           end
            grid on
            ax = gca;             % Get current axes
            ax.GridLineStyle = ':';    % (Optional) Set grid line style
            ax.LineWidth = 2;         % This affects grid line thickness and axes box
            ax.GridColor = [0 0 0];
            x0=10;
            y0=10;
            width=1000;
            height=400;      
            pln=pln+1;          
            set(gcf,'position',[x0,y0,width,height])
            hold off
end
saveas(figure(1),fullfile(spath,['AR_06CVAL.eps']),'epsc');
